<?php

class Core_Backend_Component_Permission_View_Account_Batchedit extends Core_Backend_Share_View_Form {
    
    protected function buildToolbar($toolbar) {
    	$group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('permission/account/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.save'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'batchsave')."')");
    }    

    protected function buildForm($form){
        $form->setAction($this->getUrl())->setId('account_form');
        $form->addSelectField($this->__('permission.label.accountGrade'), 'grade', 'account[grade]', TRUE)
                ->addRequiredRule()
                ->setOption($this->__('permission.label.normalAccount'), 'na')
                ->setOption($this->__('permission.label.superAdmin'), 'sa');
        $form->addSelectField($this->__('permission.label.isavailable'), 'status', 'account[status]')
                ->setOption($this->__('status.boolean.1'),'enable')
                ->setOption($this->__('status.boolean.0'),'disable');
        $form->addComboTreeField($this->__('permission.label.role'), 'role_ids', 'account[role_ids][]')
        		->setDefaultOption('', '--')
                ->bindData($this->getRoles()->toArray(), 0, array('valueKey' => 'id', 'textKey' => 'name', 'parentKey' => 'parent_id', 'childKey' => 'id'))
                ->setMultiple(TRUE)
                ->setSize(10);
        foreach($this->getAccounts() as $account){
        	$form->addHiddenField('id_'.$account->getId(), 'ids[]', $account->getId());
        }
    }
}